package org.pz.handler;

import com.alibaba.fastjson2.JSONObject;
import org.pz.entity.MallResult;
import org.pz.http.HttpUtils;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 未认证的处理 401
 * */
public class MallStatusEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        //响应给前端
        HttpUtils.parseResponseBody(JSONObject.toJSONString(MallResult.forbidden()), response);
    }
}
